package com.fkc.javahansoulbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.fkc.javahansoulbms.entity.Admin;
import com.fkc.javahansoulbms.exception.ComFoundException;
import com.fkc.javahansoulbms.mapper.AdminMapper;
import com.fkc.javahansoulbms.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl implements AdminService {
	
	@Autowired
	private AdminMapper adminMapper;
	
	/**
	 * 实现管理员登陆注册功能
	 * @param adminAccount 管理员账号
	 * @param adminPassword 管理员密码
	 * @return 返回管理员信息
	 */
	public Admin loginAdmin(String adminAccount, String adminPassword) {
		// 查询是否有该管理员
		Admin admin = adminMapper.selectOne(
				new LambdaQueryWrapper<Admin>()
						.eq(Admin::getAdminAccount, adminAccount)
						.eq(Admin::getAdminPassword, adminPassword)
		);
		
		if (admin == null) {
			throw new ComFoundException("未找到对应管理员信息，请检测账号！");
		}
		
		// 检查密码是否正确
		if (!admin.getAdminPassword().equals(adminPassword)) {
			throw new ComFoundException("密码错误");
		}
		
		return admin;
	}
}
